package com.ruoyi.cms.controller.api;

import com.alibaba.fastjson.JSON;
import com.ruoyi.cms.domain.request.ArticleDraftReqDTO;
import com.ruoyi.cms.service.impl.ArticleDraftServiceImpl;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 对外接口
 *
 * @author Lorry
 * @since 2020-12-11 22:09:36
 */
@RestController
@RequestMapping("api/art")
public class ArticleDraftApiController extends BaseController {
    @Autowired
    private ArticleDraftServiceImpl articleDraftService;

    @PostMapping("add")
    public AjaxResult add(@RequestBody ArticleDraftReqDTO reqDTO) {
        logger.info("add draft: {}", JSON.toJSONString(reqDTO));
        int b = articleDraftService.batchAddDrafts(reqDTO);
        if (b == -1) {
            logger.error("无效数据|账号后台未设置关注|非原创文章|文章含音视频内容|文章已存在等，忽略！");
            return error(AjaxResult.Type.ERROR, "无效数据|账号后台未设置关注|非原创文章|文章含音视频内容|文章已存在等，忽略！");
        } else if (b > 0) {
            logger.debug("上报成功");
            return success("上报成功");
        } else {
            return error();
        }
    }
}
